<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <title>${data.id==null?'添加':'修改'}监控明细关联配置</title>
</head>

<body menuId="4020">
<!--Action boxes-->
<div class="container-fluid">
    <hr>
    <div class="row-fluid">
        <div class="span12">
            <div class="widget-box">
                <div class="widget-title">
						<span class="icon"> <i class="fa fa-list"></i>
						</span>
                    <h5></h5>
                </div>
                <div class="widget-content nopadding">
                    <form class="form-horizontal" method="post" action="#" id="mainForm">
                        <div class="control-group">
                            <label class="control-label"><span class="red">*</span>列名</label>
                            <div class="controls">
                                <input type="text" name="fieldName" value="${data.fieldName}" maxlength="30"/>
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label">类型</label>
                            <div class="controls">
                                <u:select id="fieldType"
                                          data="[{value:'0',text:'int'},{value:'1',text:'double'},{value:'2',text:'string'}]"
                                          value="${data.fieldType}" showAll="false"/>
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label">所属表名</label>
                            <div class="controls">
                                <u:select id="measurement" data="[{value:'0',text:'receive_mt_sms'},
                                                                    {value:'1',text:'access_sms_report'},{value:'2',text:'accee_mo_sms'},
                                                                    {value:'3',text:'access_audit_sms'},{value:'4',text:'access_intercept_sms'},
                                                                    {value:'5',text:'access_sms_submit'},{value:'6',text:'reback_sms_submit'},
                                                                    {value:'7',text:'channel_sms_submit'},{value:'8',text:'channel_sms_subret'},
                                                                    {value:'9',text:'channel_sms_report'},{value:'10',text:'middleware_alarm'}]"
                                          value="${data.measurement}" showAll="false"/>
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label">状态</label>
                            <div class="controls">
                                <u:select id="state"
                                          data="[{value:'0',text:'关闭'},{value:'1',text:'开启'}]"
                                          value="${data.state}" showAll="false"/>
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label">描述</label>
                            <div class="controls">
                                <input type="text" name="remark" value="${data.remark}"
                                       maxlength="100"/>
                            </div>
                        </div>

                        <div class="form-actions">
                            <input type="hidden" name="id" value="${data.id}"/>
                            <input type="button" onclick="save(this);" value="保  存" class="btn btn-success">
                            <input type="button" value="取 消" class="btn btn-error" onclick="back()"/>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    var validate;
    $(function () {

        $.validator.defaults.ignore = "";
        //表单验证规则
        validate = $("#mainForm").validate({
            rules: {
                fieldName: {
                    required: true,
                    maxlength: 30
                },
                fieldType: {
                    required: true
                },
                measurement: {
                    required: true,
                },
                state: {
                    required: true,
                },
                remark: {
                    maxlength: 100
                }
            }
        });
    });

    //保存
    function save(btn) {
        $("#msg").hide();
        if (!validate.form()) {
            return;
        }

        //列名校验
        var fieldName = $('input[name = fieldName]').val();
        var regs = /^[0-9a-zA-Z_-]{1,}$/;
        if(fieldName != "*" && !regs.test(fieldName)) {
            layer.msg("列名只能包含英文、下划线、短横、数字或只填*", {icon: 2});
            return;
        }

        var options = {
            beforeSubmit: function () {
                $(btn).attr("disabled", true);
            },
            success: function (data) {
                if (data.code == 200) {
                    layer.msg(data.msg,{icon:1});
                    back();
                }else{
                    $(btn).removeAttr("disabled", true);
                    layer.msg(data.msg, {icon:2});
                    return;
                }
            },
            url: "${ctx}/componentConf/monitorDetailRefConf/save",
            type: "post",
            timeout: 30000
        };
        $("#mainForm").ajaxSubmit(options);
    }


</script>
</body>
</html>